package com.boyadegroot.divelog.ui;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.widget.TextView;

import com.boyadegroot.divelog.R;
import com.boyadegroot.divelog.models.Dive;

public class DiveDetails extends ActionBarActivity {

    private static final String TAG = DiveDetails.class.getName();

    private TextView mSiteName;
    private TextView mDiveNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Log.v(TAG, "onCreate(Bundle savedInstanceState)");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_dive_details);
        getViewElements();
        int diveNumber = getIntent().getIntExtra("number", 0);
        Dive dive = getIntent().getParcelableExtra("dive");
        createView(diveNumber,dive);
    }

    private void createView(int diveNumber, Dive dive) {
        Log.d(TAG, "createView(dive = " + dive + ")");
        if (diveNumber == 0) {
            throw new Error("diveNumber is 0");
        }
        if (dive == null) {
            throw new Error("Dive is null");
        }
        mSiteName.setText(dive.getSite().getName());
        mDiveNumber.setText(diveNumber + ".");
    }

    private void getViewElements() {
        mSiteName = (TextView) findViewById(R.id.sitename);
        mDiveNumber = (TextView) findViewById(R.id.divenumber);
    }
}